package logic

import (
	"context"
	"zhaowei/api/internal/svc"
	"zhaowei/api/internal/types"
	"zhaowei/baidurpc/baidurpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PostAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPostAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PostAddLogic {
	return &PostAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PostAddLogic) PostAdd(req *types.PostAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	sms, err := l.svcCtx.BaiDuRpc.PostAdd(l.ctx, &baidurpc.PostAddRequest{
		UserId: int64(req.UserId),
		Name:   req.Name,
		Image:  req.Image,
		Like:   int64(req.Like),
		BarId:  int64(req.BarId),
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: "添加失败",
			Data:    nil,
		}, nil
	} else {
		return &types.Response{
			Code:    200,
			Message: "添加成功",
			Data:    sms,
		}, nil
	}
	return
}
